﻿using OpenPowerPoint;
using NUnit.Framework;
using OpenPowerPoint.Exceptions;
using OpenPowerPoint.Slides;

namespace OpenPowerPointTest.Initialisation
{
    /// <summary>
    /// Tests for a new initialized Presentation
    /// </summary>
    [TestFixture]
    [Category("Integration: Initialisation")]
    class NewPresentationInitialisation
    {
        private Presentation _presentation;

        #region Setup/Teardown
        [SetUp]
        public void SetUp()
        {
            _presentation = new Presentation(Presentation.PresentationType.Presentation);
        }

        [TearDown]
        public void TearDown()
        {

        }
        #endregion

        /// <summary>
        /// Test for the right Presentation type
        /// </summary>
        /// <remarks><seealso cref="Presentation.Type"/></remarks>
        [Test]
        [TestCase(Presentation.PresentationType.AddIn)]
        [TestCase(Presentation.PresentationType.MacroPresentation)]
        [TestCase(Presentation.PresentationType.Template)]
        public void PresentationType(Presentation.PresentationType type)
        {
            var presentation = new Presentation(type);
            Assert.AreEqual(type, presentation.Type);
        }

        /// <summary>
        /// Test for the right Filename
        /// </summary>
        /// <remarks><seealso cref="Presentation.Filename"/></remarks>
        [Test]
        public void FileNameSet()
        {
            Assert.AreEqual("", _presentation.Filename, "Filename for empty presentation");
        }

        /// <summary>
        /// Test for the right number of groups
        /// </summary>
        /// <remarks><seealso cref="Presentation.Groups"/></remarks>
        [Test]
        public void GroupsCount()
        {
            Assert.AreEqual(1, _presentation.Groups.Count, "Wrong number of initial groups");
        }

        /// <summary>
        /// Test for the right number of slides in the first group
        /// </summary>
        /// <remarks><seealso cref="SlideGroup.Slides"/></remarks>
        [Test]
        public void SlideCount()
        {
            Assert.AreEqual(0, _presentation.Groups[0].Slides.Count, "Wrong number of initial slides");
        }

        /// <summary>
        /// Test for the right number of slide masters
        /// </summary>
        /// <remarks><seealso cref="Presentation.SlideMasters"/></remarks>
        [Test]
        public void SlideMasterCount()
        {
            Assert.IsNotNull(_presentation.SlideMasters, "SlideMasters not initialized");
            Assert.AreEqual(1, _presentation.SlideMasters.Count, "Wrong number of initial Master Slides");
        }

        /// <summary>
        /// Test for the right number of layouts in the first slide master
        /// </summary>
        /// <remarks><seealso cref="SlideMaster.Layouts"/></remarks>
        [Test]
        public void SlideLayoutCount()
        {
            Assert.AreEqual(1, _presentation.SlideMasters[0].Layouts.Count, "Wrong number of initial Layouts");
        }


        [Test]
        public void DeleteLastLayout()
        {
            Assert.Throws<ListNotClearable>(() => _presentation.SlideMasters[0].Layouts.RemoveAt(0),"Last layout removed");
        }

        [Test]
        public void DeleteLastMaster()
        {
            Assert.Throws<ListNotClearable>(() => _presentation.SlideMasters.RemoveAt(0),"Last master removed");
        }

        [Test]
        public void DeleteLastGroup()
        {
            Assert.Throws<ListNotClearable>(() => _presentation.Groups.RemoveAt(0),"Last group removed");
        }
    }
}
